import { defineStore } from 'pinia'
import Localcache from '../utils/localcache'

interface IUserInfo {
  id?: number
  name?: string
  token?: string
}

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: {} as IUserInfo
  }),
  actions: {
    updateUserInfo(res: IUserInfo) {
      console.log('更新的数据是', res)
      this.userInfo = res
	   Localcache.saveUserInfo(res)
    },
    loadlocal() {
      if (Localcache.getUserInfo()) {
        this.updateUserInfo(Localcache.getUserInfo())
      }
    }
  }
})
